package com.dongzili.demo.customer.fulltext.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dongzili.demo.common.vo.ApiResponse;
import com.dongzili.demo.customer.fulltext.service.RedisFullTextUtils;
import com.dongzili.demo.customer.redis.model.InterfaceLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/interface")
public class InterfaceLogController {

    private final Class<?> tClass = InterfaceLog.class;

    @GetMapping("/syncIndex")
    public ApiResponse<?> syncIndex(){
        try {
            RedisFullTextUtils.getService(tClass).syncIndex();
            return ApiResponse.success();
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }


    @GetMapping("/search")
    public ApiResponse<?> search(@RequestParam("text") String text, @RequestParam(value = "current", defaultValue = "1") int current, @RequestParam(value = "size", defaultValue = "10") int size){
        Page<?> page = RedisFullTextUtils.getService(tClass).search(text, current, size);
        return ApiResponse.success(page);
    }


}
